package br.inatel.ec203.projeto.view;

import javax.swing.table.DefaultTableModel;

import br.inatel.ec203.projeto.control.ArmarioDAO;
import br.inatel.ec203.projeto.model.Item;

public abstract class Util {

	public static void addRow(Item componente, DefaultTableModel componentTableModel) {
		String[] row = new String[] {componente.getDescricao(), componente.getValor(), componente.getPartNumber(), Integer.toString(componente.getQuantidade()), componente.getLocalizacao()};
		componentTableModel.addRow(row);
	}
	
	public static Item findComponentInArrayList(String value, String partNumber) {
		ArmarioDAO armarioDAO = new ArmarioDAO();
		Item result = null;
		for (Item componente : armarioDAO.getComponentes()) {
			if (componente.getValor().equals(value) && componente.getPartNumber().equals(partNumber)) {
				result = componente;
			}
		}
		return result;
	}
	
	public static boolean findComponentByPartNumber(String partNumber) {
		boolean result = false;
		ArmarioDAO armarioDAO = new ArmarioDAO();
		
		for(Item component : armarioDAO.getComponentes()){
			if (component.getPartNumber() != null && component.getPartNumber().toLowerCase().equals(partNumber.trim())) {
				result = true;
			}
		}
		
		return result;
	}
	
	public static boolean findComponentBylocalization(String localization) {
		boolean result = false;
		ArmarioDAO armarioDAO = new ArmarioDAO();
		
		for(Item component : armarioDAO.getComponentes()){
			if (component.getLocalizacao() != null && component.getLocalizacao().toLowerCase().equals(localization.trim())) {
				result = true;
			}
		}
		return result;
	}
	
	public static String addInArrayList(String element) {
		if (element == null || element.trim().isEmpty()) {
			element = " ";
		}
		
		return element;
	}
}










